/***************************************************************************
 *   Copyleft 2008-2009 by												   *
 *	 Iwanicki Krzysztof													   *
 *   <gamma.mini.pw.edu.pl/~iwanickik>									   *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 ***************************************************************************/
#ifndef __VSTRINGCONVERTER_H__
#define __VSTRINGCONVERTER_H__

#include "./vString.h"
#include "../Macros/vMemoryMacros.h"

namespace Vendetta {
	class vColor;

	/*! \class vStringConverter
	 *  \brief A vStringConverter class converts various types to vString and from vString.
	 *  
	 *  
	 *  Each class which can be written in text format should has it as friend class.
	 *  
	 */
	class vStringConverter {
	public:
		/*! \enum vStringConverter::eBoolType
		 *  \brief A eBoolType enum is used for bool type conversion.
		 *
		 *  There are three types of bool conversion:
		 *  1. VBT_TRUEFALSE_C - true, false mapping, first letter upper case (Cammel) - default.
		 *	2. VBT_TRUEFALSE_U - true, false upper case mapping.
		 *	3. VBT_TRUEFALSE_L - true, false lower case mapping.
		 *  4. VBT_YESNO_C - yes, no mapping, first letter upper case (Cammel).
		 *  5. VBT_YESNO_U - yes, no mapping upper case mapping.
		 *  6. VBT_YESNO_L - yes, no mapping lower case mapping.
		 *  7. VBT_ONEZERO - 1, 0 mapping.
		 *  
		 *  Each class which can be written in text format should has it as friend class.
		 *  
		 */
		enum eBoolType {
			VBT_TRUEFALSE_U,
			VBT_TRUEFALSE_L,
			VBT_TRUEFALSE_C,
			VBT_YESNO_U,
			VBT_YESNO_L,
			VBT_YESNO_C,
			VBT_ONEZERO
		};

		/*! \enum vStringConverter::eColorType
		 *  \brief A eColorType enum is used for vColor type conversion.
		 *
		 *  There are three types of color conversion:
		 *  1. VCT_SPACE - each color separated with space, example (1 0.9 0.1 0).
		 *  2. VCT_COMMA - each color separated with comma, example (1,0.9,0.1,0), all the spaces will be erased.
		 *  3. VCT_SEMICOLON - each color separated with space, example (1;0.9;0.1;0), all the spaces will be erased.
		 *  
		 *  Each class which can be written in text format should has it as friend class.
		 *  
		 */
		enum eColorType {
			VCT_SPACE,
			VCT_COMMA,
			VCT_SEMICOLON
		};

	public:
		/*! \brief Destructor.
		 *
		 */
		~vStringConverter();

		/*! \brief Converts vReal to vString.
		 *
		 *			 
		 *  \param		rVal					Value to write as string.
		 *  \param		usPrecision				Precision, default is 6.
		 *  \param		usWidth					Width, default is 0, it mean no filling with extra characters.
		 *  \param		flags					std::ios::fmtflags for stream manipulations, default 0.
		 *  \sa			std::stringstream
		 *	\sa			vString.
		 */
		static vString ToString(vReal rVal, vUShort usPrecision = 6, vUShort usWidth = 0, vChar cFill = ' ', 
            std::ios::fmtflags flags = std::ios::fmtflags(0));

		/*! \brief Converts int to vString.
		 *
		 *			 
		 *  \param		iVal					Value to write as string.
		 *  \param		usWidth					Width, default is 0, it mean no filling with extra characters.
		 *  \param		flags					std::ios::fmtflags for stream manipulations, default 0.
		 *  \sa			std::stringstream
		 *	\sa			vString.
		 */
		static vString ToString(vInt iVal, vUShort usWidth = 0, vChar cFill = ' ', 
            std::ios::fmtflags flags = std::ios::fmtflags(0));

		/*! \brief Converts unsigned int to vString.
		 *
		 *			 
		 *  \param		uiVal					Value to write as string.
		 *  \param		usWidth					Width, default is 0, it mean no filling with extra characters.
		 *  \param		flags					std::ios::fmtflags for stream manipulations, default 0.
		 *  \sa			std::stringstream
		 *	\sa			vString.
		 */
		static vString ToString(vUInt uiVal, vUShort usWidth = 0, vChar cFill = ' ', 
            std::ios::fmtflags flags = std::ios::fmtflags(0));

		/*! \brief Converts long to vString.
		 *
		 *			 
		 *  \param		lVal					Value to write as string.
		 *  \param		usWidth					Width, default is 0, it mean no filling with extra characters.
		 *  \param		flags					std::ios::fmtflags for stream manipulations, default 0.
		 *  \sa			std::stringstream
		 *	\sa			vString.
		 */
		static vString ToString(vLong lVal, vUShort usWidth = 0, vChar cFill = ' ', 
            std::ios::fmtflags flags = std::ios::fmtflags(0));
		
		/*! \brief Converts unsigned int to vString.
		 *
		 *			 
		 *  \param		ulVal					Value to write as string.
		 *  \param		usWidth					Width, default is 0, it mean no filling with extra characters.
		 *  \param		flags					std::ios::fmtflags for stream manipulations, default 0.
		 *  \sa			std::stringstream
		 *	\sa			vString.
		 */
		static vString ToString(vUInt32 ulVal, vUShort usWidth = 0, vChar cFill = ' ', 
            std::ios::fmtflags flags = std::ios::fmtflags(0));

		/*! \brief Converts bool to vString.
		 *
		 *			 
		 *  \param		bVal					Value to write as string.
		 *  \param		eWriteType				Sets write format, default VBT_TRUEFALSE_C.		 
		 *	\sa			vString.
		 *  \sa			vStringConverter::eBoolType.
		 */
		static vString ToString(vBool bVal, eBoolType eWriteType = VBT_TRUEFALSE_C);

		/*! \brief Converts vColor to vString.
		 *
		 *			 
		 *  \param		bVal					Value to write as string.
		 *  \param		eWriteType				Sets write format, default VCT_COMMA.		 
		 *	\sa			vString.
		 *  \sa			vStringConverter::eColorType.
		 */
		static vString ToString(vColor color, eColorType colorType = VCT_COMMA);

		/*! \brief Converts vString to int.
		 *
		 *			 
		 *  \param		str						String value to convert.
		 *  \param		*bResultOk				Ptr to bool, set to true if conversion accomplished successfully, false otherwise.		 
		 *	\sa			vString.
		 */
		static vInt ToInt(const vString& str, vBool *bResultOk);

		/*! \brief Converts vString to unsigned int.
		 *
		 *			 
		 *  \param		str						String value to convert.
		 *  \param		*bResultOk				Ptr to bool, set to true if conversion accomplished successfully, false otherwise.		 
		 *	\sa			vString.
		 */
		static vUInt ToUInt(const vString& str, vBool *bResultOk);

		/*! \brief Converts vString to long.
		 *
		 *			 
		 *  \param		str						String value to convert.
		 *  \param		*bResultOk				Ptr to bool, set to true if conversion accomplished successfully, false otherwise.		 
		 *	\sa			vString.
		 */
		static vLong ToLong(const vString& str, vBool *bResultOk);

		/*! \brief Converts vString to unsigned long.
		 *
		 *			 
		 *  \param		str						String value to convert.
		 *  \param		*bResultOk				Ptr to bool, set to true if conversion accomplished successfully, false otherwise.		 
		 *	\sa			vString.
		 */
		static vUInt32 ToUInt32(const vString& str, vBool *bResultOk);

		/*! \brief Converts vString to vReal.
		 *
		 *			 
		 *  \param		str						String value to convert.
		 *  \param		*bResultOk				Ptr to bool, set to true if conversion accomplished successfully, false otherwise.		 
		 *	\sa			vString.
		 */
		static vReal ToReal(const vString& str, vBool *bResultOk);

		/*! \brief Converts vString to bool.
		 *
		 *			 
		 *  \param		str						String value to convert.
		 *  \param		*bResultOk				Ptr to bool, set to true if conversion accomplished successfully, false otherwise.		 
		 *	\sa			vString.
		 */
		static vBool ToBool(const vString& str, vBool *bResultOk);

		/*! \brief Converts vString to vColor.
		 *
		 *	String color for parse should not have some sort of brackets. 
		 *	(1 0.5 0.6) - wrong
		 *	1.0 0.0 1 0.7 - good
		 *	Fourth parameter is not required, if it is not specified the default value is 1.0 like in vColor constructor.
		 *	Color is written and loaded as follows:
		 *	R G B A
		 *	all parameters are from [0, 1] range.
		 *			 
		 *  \param		str						String value to convert.
		 *  \param		*bResultOk				Ptr to bool, set to true if conversion accomplished successfully, false otherwise.		 
		 *	\sa			vString.
		 *	\sa			vColor.
		 */
		static vColor ToColor(const vString& str, vBool *bResultOk);

	private:
		vStringConverter();		
	};
}

#endif // __VSTRINGCONVERTER_H__